<template>
  <div class="app-container">
    <el-form :inline="true" :model="filters" class="demo-form-inline filter-container">
      <el-form-item prop="dateType">
        <el-select v-model="filters.dateType">
          <el-option
            label="新建时间"
            :value="1">
          </el-option>
          <el-option
            label="修改时间"
            :value="2">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="filters.date"
          class="filter-item"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          align="right">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="教程主题：">
        <el-input v-model="filters.theme"></el-input>
      </el-form-item>
      <el-form-item label="充值教程类别：">
        <el-select v-model="filters.rechargeType" filterable>
          <el-option v-for="item in consts.RECHARGE_TYPE_NAMES"
                     :key="item.value"
                     :label="item.title"
                     :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-button type="primary" v-waves icon="el-icon-search" @click="gridSearch">搜索</el-button>
    </el-form>

    <el-table :data="tableData.items" v-loading="loading" element-loading-text="给我一点时间" border fit
              highlight-current-row
              style="width: 100%">
      <el-table-column label="新建时间" align="center">
        <template slot-scope="{row}">
          {{row.createTime | toTime}}
        </template>
      </el-table-column>
      <el-table-column label="显示端" align="center">
        <template slot-scope="{row}">
          {{row.device | toConverter('DEVICE_TYPE')}}
        </template>
      </el-table-column>
      <el-table-column label="充值教程类别" align="center">
        <template slot-scope="{row}">
          {{row.rechargeType | toConverter('RECHARGE_TYPE_NAMES')}}
        </template>
      </el-table-column>
      <el-table-column label="教程主题" align="center" >
        <template slot-scope="{row}">
          {{row.theme}}
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center">
        <template slot-scope="{row}">
          {{row.lastModifyTime | toTime}}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="300px">
        <template slot-scope="scope">
          <el-button type="text"
                     @click="openDialog({dialogName: 'recharge-help-edit',
                     props: scope.row
                     })">
            修改
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog :visible.sync="dialogVisible" :before-close="() => {dialogVisible = false}">
      <recharge-help-edit style="max-height:60vh; overflow: auto" :id="dialogProps.id"
                 @on-success="dialogVisible = false;doGet({action: 'getGrid'})"
                   v-if="dialogName === 'recharge-help-edit'"></recharge-help-edit>
    </el-dialog>
  </div>
</template>

<script>
  import {form, grid, dialog} from '@/build';

  import {
    noticeRechargeHelpListApi as listApi,
  } from '@/services/api/notice';

  import RechargeHelpEdit from './rechargeHelpEdit';

  export default {
    name: 'recharge-help-setting-list',

    mixins: [form, grid, dialog],

    components: {
      RechargeHelpEdit,
    },

    props: {
      departmentId: Number,
      workId: Number,
    },

    data() {
      return {
        tableData: {
          items: [],
          total: 0
        },
        filters: {
          dateType: 1,
          date: undefined,
          rechargeType: undefined,
          theme: undefined,
        },
      }
    },

    methods: {
    },

    mounted() {
      this.bindGet(listApi, 'tableData', {
        action: 'getGrid',
        sendingData: 'filters'
      });

      this.getAll();
    }
  }
</script>
